In this step of the tutorial you implement the functionality that handles the interactions in the description panel of the application:
To create the interaction for the widget description panel:
onProjectLoaded()
function add the event handler for the Back button.virtual void onProjectLoaded() KZ_OVERRIDE
{
...
// Add the handler for the Back button.
m_backButton->addMessageHandler(Button3D::PressedMessage, bind(&ProgrammerTutorialApplication::onBackButtonClicked, this, placeholders::_1));
}
ProgrammerTutorialApplication
class after the onListBoxItemSelected()
function implement the event handler for the Back button click message.false
when the animation is finished. Next you make the node transparent by setting its opacity to 0.0f
. The Widget Description Layer node is hidden, but remains visible to block user input until the animation is finished.class ProgrammerTutorialApplication : public ExampleApplication { ... // The handler for the Button.Pressed message from the Back button. // Moves the selected list box item back to its position. void onBackButtonClicked(ButtonConcept::PressedMessageArguments& /*messageArguments*/) { // De-select the previously selected list box item. m_widgetList->selectItem(nullopt); // Remove old playbacks to reset the values. removePlaybacks(); // Start the animation for the camera in reverse direction. PropertyAnimationTimelineSharedPtr cameraTimeline = PropertyAnimationTimeline::create(getDomain(), ".", Node3D::RenderTransformationProperty, m_cameraAnimation); cameraTimeline->setDirectionBehavior(Timeline::DirectionBehaviorReverse); SceneGraphTimelinePlaybackContext cameraContext(*m_camera); m_cameraPlayback = cameraTimeline->createPlayback(cameraContext); getDomain()->getRootTimelineClock()->addTimelinePlayback(m_cameraPlayback); // Start the animation for the selected item in reverse direction. PropertyAnimationTimelineSharedPtr selectedItemTimeline = PropertyAnimationTimeline::create(getDomain(), ".", Node3D::LayoutTransformationProperty, m_selectedItemAnimation); selectedItemTimeline->setDirectionBehavior(Timeline::DirectionBehaviorReverse); SceneGraphTimelinePlaybackContext selectedItemContext(*m_selectedItem); m_widgetHighlightPlayback = selectedItemTimeline->createPlayback(selectedItemContext); getDomain()->getRootTimelineClock()->addTimelinePlayback(m_widgetHighlightPlayback); // Start the animation to hide the Widget Description Layer. PropertyAnimationTimelineSharedPtr widgetDescriptionVisibilityTimeline = PropertyAnimationTimeline::create(getDomain(), ".", Node::VisibleProperty, m_widgetDescriptionVisibilityAnimation); SceneGraphTimelinePlaybackContext listBoxContext(*m_widgetDescriptionNode); m_widgetDescriptionVisibilityPlayback = widgetDescriptionVisibilityTimeline->createPlayback(listBoxContext); getDomain()->getRootTimelineClock()->addTimelinePlayback(m_widgetDescriptionVisibilityPlayback); // Make the Widget Description Layer transparent. m_widgetDescriptionNode->setProperty(Node::OpacityProperty, 0.0f); } };
void onListBoxItemSelected(ListBoxConcept::itemSelectedMessageArguments& messageArguments) { ... if (selectedItemIndex) { ... // Show the widget description by setting the Widget Description Layer visible. if (m_widgetDescriptionVisibilityPlayback) { ... } ... // Make the Widget Description Layer opaque. m_widgetDescriptionNode->setProperty(Node::OpacityProperty, 1.0f); } }
onBackButtonClicked()
function add a function which removes the old playbacks from the timeline clock to reset the camera values:// Remove old playbacks from the timeline clock. void removePlaybacks() { TimelineClockSharedPtr timelineClock = getDomain()->getRootTimelineClock(); if (m_cameraPlayback) { timelineClock->removeTimelinePlayback(*m_cameraPlayback); m_cameraPlayback.reset(); } if (m_widgetHighlightPlayback) { timelineClock->removeTimelinePlayback(*m_widgetHighlightPlayback); m_widgetHighlightPlayback.reset(); } if (m_backButtonEnablePlayback) { timelineClock->removeTimelinePlayback(*m_backButtonEnablePlayback); m_backButtonEnablePlayback.reset(); } if (m_widgetDescriptionVisibilityPlayback) { timelineClock->removeTimelinePlayback(*m_widgetDescriptionVisibilityPlayback); m_widgetDescriptionVisibilityPlayback.reset(); } }